#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2023/7/22 16:08
# @Author  : YueJian
# @File    : http_base.py
# @Description :
# !/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2023/7/22 16:08
# @Author  : YueJian
# @File    : http_base.py
# @Description :

from enum import Enum

__all__ = ["HttpCode"]


class HttpCode(Enum):
    # 成功类
    SUCCESS = (200, "成功")
    ADD_SUCCESS = (200, "添加成功")
    UPDATE_SUCCESS = (200, "修改成功")
    REMOVE_SUCCESS = (200, "删除成功")

    # 失败类
    FAILED = (400, "失败")
    ADD_FAILED = (400, "添加失败")
    UPDATE_FAILED = (400, "修改失败")
    REMOVE_FAILED = (400, "删除失败")
    PARAMS_VALID_ERROR = (400, "参数校验错误")
    PARAMS_TYPE_ERROR = (400, "参数类型错误")
    REQUEST_METHOD_ERROR = (400, "请求方法错误")
    ASSERT_ARGUMENT_ERROR = (400, "断言参数错误")

    # 登录相关
    LOGIN_ACCOUNT_ERROR = (400, "登录账号或密码错误")
    LOGIN_CODE_ERROR = (999, "验证码错误")
    LOGIN_DISABLE_ERROR = (400, "登录账号已被禁用了")
    TOKEN_EMPTY = (401, "token参数为空")
    TOKEN_INVALID = (401, "token参数无效")
    LOGIN_EXPIRED = (401, "登录过期")
    LOGIN_REPEAT = (555, "账号在其他地方登录，你已经被下线")
    NO_PERMISSION = (403, "无相关权限")

    # 错误类
    REQUEST_404_ERROR = (404, "请求接口不存在")
    HTTP_400_BAD_REQUEST = (400, "请求错误")
    TOO_MANY_REQUESTS = (429, "请勿频繁请求")

    # 系统错误
    SYSTEM_ERROR = (500, "系统错误")
    SYSTEM_GATEWAY = (501, "表示服务器作为网关或代理，从上游服务器收到了无效响应。")
    SYSTEM_TIMEOUT_ERROR = (504, "请求超时")

    def __init__(self, code: int, msg: str):
        self.code = code
        self.msg = msg

    def __repr__(self):
        return f"{self.__class__.__name__}.{self.name}: {self.code} - {self.msg}"

    def __str__(self):
        return f"{self.code}: {self.msg}"
